/*
 * Copyright Notice ====================================================
 * This file contains proprietary information of Hewlett-Packard Co.
 * Copying or reproduction without prior written approval is prohibited.
 * Copyright (c) 2014 All rights reserved. =============================
 */

package com.jeestrap.common.smartcoder.gui;

import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jeestrap.common.smartcoder.database.DbUtil;

public abstract class BaseFrame extends JFrame {

	/**
	 * serialVersionUID long
	 */
	private static final long serialVersionUID = -1127430781813481610L;

	public BaseFrame() throws HeadlessException {
		super();
		// 设置框架窗体的事件监听(关闭窗体事件)
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				DbUtil.realseConnection();
				System.exit(0);
				System.out.println("JeeWeb - 代码生成器   END");
			}
		});

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("JeeWeb - 代码生成器");
		setIconImage(new ImageIcon(ClassLoader.getSystemResource("logo.png")).getImage());

		Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
		// int width = (int)(localDimension.getWidth());
		// int height = (int)(localDimension.getHeight());
		int width = 900;
		int height = 600;
		// this.setSize((int)localDimension.getWidth(), (int)localDimension.getHeight());
		this.setBounds(0, 0, width, height);
		this.setSize(width, height);
		this.setLocation((int)(localDimension.getWidth() - this.getWidth()) / 2,
			(int)(localDimension.getHeight() - this.getHeight()) / 2);
		
		getContentPane().add("North", createNaviPane());
		getContentPane().add("Center", createContentPane());
		getContentPane().add("South", createBtnPane());
	}

	/**
	 * 下面是导航面板的创建过程
	 * 
	 * @return
	 * 
	 * @since
	 */
	public abstract JPanel createNaviPane();

	/**
	 * 下面是按钮面板的创建过程
	 * 
	 * @return
	 * 
	 * @since
	 */
	public abstract JPanel createBtnPane();
	
	/**
	 * 下面是内容面板的创建过程
	 * 
	 * @return
	 * 
	 * @since
	 */
	public abstract JComponent createContentPane();
}
